package com.dstats.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;

import com.dstats.R;

public class ItemsFragment extends Fragment {
	private WebView webView;
	private ProgressBar loadingProgressBar;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 View rootView = inflater.inflate(R.layout.simple_web_view, container, false);
			loadingProgressBar=(ProgressBar) rootView.findViewById(R.id.progressBarWebView); 
			loadingProgressBar.setMax(100);
		webView = (WebView) rootView.findViewById(R.id.webView1);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.getSettings().setSupportZoom(true); 
		webView.getSettings().setBuiltInZoomControls(true);
		webView.getSettings().setUseWideViewPort(true);
		webView.getSettings().setLoadWithOverviewMode(true);
		webView.getSettings().setUserAgentString("Chrome");
		webView.loadUrl("http://www.dota2.com/items");
		webView.setWebChromeClient(new WebChromeClient() {

			   @Override
			   public void onProgressChanged(WebView view, int newProgress) {

			   super.onProgressChanged(view, newProgress);

			   loadingProgressBar.setProgress(newProgress);
			   //loadingTitle.setProgress(newProgress);
			   // hide the progress bar if the loading is complete

			   if (newProgress == 100) {
				   loadingProgressBar.setVisibility(View.GONE);
				   } else{
				   loadingProgressBar.setVisibility(View.VISIBLE); 
				   }
			   }
			   });

		return rootView;
	}
	
}
